home *** CD-ROM | disk | FTP | other *** search
/ Hardcore Visual Basic 5.0 (2nd Edition) / Hardcore Visual Basic 5.0 - Second Edition (1997)(Microsoft Press).iso / Code / TFolder.frm < prev    next >
Text File  |  1997-06-14  |  11KB  |  361 lines

  1. VERSION 5.00
  2. Begin VB.Form FShellFolder 
  3.    Caption         =   "Test Shell Folders"
  4.    ClientHeight    =   5400
  5.    ClientLeft      =   1500
  6.    ClientTop       =   4110
  7.    ClientWidth     =   8490
  8.    Icon            =   "TFolder.frx":0000
  9.    LinkTopic       =   "Form1"
  10.    ScaleHeight     =   5400
  11.    ScaleWidth      =   8490
  12.    Begin VB.ComboBox cboWalk 
  13.       Height          =   315
  14.       ItemData        =   "TFolder.frx":0CFA
  15.       Left            =   120
  16.       List            =   "TFolder.frx":0D07
  17.       Style           =   2  'Dropdown List
  18.       TabIndex        =   12
  19.       Top             =   2604
  20.       Width           =   1200
  21.    End
  22.    Begin VB.CommandButton cmdBrowse 
  23.       Caption         =   "...  "
  24.       BeginProperty Font 
  25.          Name            =   "MS Sans Serif"
  26.          Size            =   8.25
  27.          Charset         =   0
  28.          Weight          =   700
  29.          Underline       =   0   'False
  30.          Italic          =   0   'False
  31.          Strikethrough   =   0   'False
  32.       EndProperty
  33.       Height          =   300
  34.       Left            =   1992
  35.       TabIndex        =   11
  36.       Top             =   3468
  37.       Width           =   330
  38.    End
  39.    Begin VB.CommandButton cmdStop 
  40.       Caption         =   "Stop!"
  41.       Height          =   336
  42.       Left            =   1416
  43.       TabIndex        =   10
  44.       Top             =   2616
  45.       Width           =   960
  46.    End
  47.    Begin VB.CommandButton cmdWalkDir 
  48.       Caption         =   "Walk One Directory"
  49.       Height          =   372
  50.       Left            =   120
  51.       TabIndex        =   9
  52.       Top             =   1614
  53.       Width           =   2256
  54.    End
  55.    Begin VB.CommandButton cmdWalkFolder 
  56.       Caption         =   "Walk One Folder"
  57.       Height          =   372
  58.       Left            =   120
  59.       TabIndex        =   8
  60.       Top             =   1104
  61.       Width           =   2256
  62.    End
  63.    Begin VB.CommandButton cmdWalkDirs 
  64.       Caption         =   "Walk All Directories"
  65.       Height          =   372
  66.       Left            =   120
  67.       TabIndex        =   7
  68.       Top             =   594
  69.       Width           =   2256
  70.    End
  71.    Begin VB.CheckBox chkPath 
  72.       Caption         =   "Use Path"
  73.       Height          =   240
  74.       Left            =   120
  75.       TabIndex        =   6
  76.       Top             =   3156
  77.       Value           =   1  'Checked
  78.       Width           =   1056
  79.    End
  80.    Begin VB.CommandButton cmdContext 
  81.       Caption         =   "Context Menu"
  82.       Height          =   372
  83.       Left            =   120
  84.       TabIndex        =   5
  85.       Top             =   2124
  86.       Width           =   2256
  87.    End
  88.    Begin VB.ListBox lstSpecial 
  89.       Height          =   1035
  90.       ItemData        =   "TFolder.frx":0D2B
  91.       Left            =   120
  92.       List            =   "TFolder.frx":0D2D
  93.       TabIndex        =   3
  94.       Top             =   4056
  95.       Width           =   2268
  96.    End
  97.    Begin VB.TextBox txtPath 
  98.       Height          =   312
  99.       Left            =   120
  100.       TabIndex        =   2
  101.       Top             =   3456
  102.       Width           =   1836
  103.    End
  104.    Begin VB.TextBox txtOut 
  105.       Height          =   5184
  106.       Left            =   2460
  107.       MultiLine       =   -1  'True
  108.       ScrollBars      =   3  'Both
  109.       TabIndex        =   1
  110.       Top             =   108
  111.       Width           =   5904
  112.    End
  113.    Begin VB.CommandButton cmdWalkFolders 
  114.       Caption         =   "Walk All Folders"
  115.       Height          =   372
  116.       Left            =   120
  117.       TabIndex        =   0
  118.       Top             =   84
  119.       Width           =   2256
  120.    End
  121.    Begin VB.Label lbl 
  122.       Caption         =   "Special folders:"
  123.       Height          =   192
  124.       Index           =   1
  125.       Left            =   108
  126.       TabIndex        =   4
  127.       Top             =   3804
  128.       Width           =   2268
  129.    End
  130. End
  131. Attribute VB_Name = "FShellFolder"
  132. Attribute VB_GlobalNameSpace = False
  133. Attribute VB_Creatable = False
  134. Attribute VB_PredeclaredId = True
  135. Attribute VB_Exposed = False
  136. Option Explicit
  137.  
  138. Implements IUseFolder
  139. Implements IUseFile
  140.  
  141. Private fWalkAll As Long
  142. Private fStop As Long
  143.  
  144. Private Sub Form_Load()
  145.     With lstSpecial
  146.         .AddItem "Desktop"
  147.         .ItemData(.NewIndex) = &H0
  148.         .AddItem "Programs"
  149.         .ItemData(.NewIndex) = &H2
  150.         .AddItem "Controls"
  151.         .ItemData(.NewIndex) = &H3
  152.         .AddItem "Printers"
  153.         .ItemData(.NewIndex) = &H4
  154.         .AddItem "Personal"
  155.         .ItemData(.NewIndex) = &H5
  156.         .AddItem "Favorites"
  157.         .ItemData(.NewIndex) = &H6
  158.         .AddItem "Startup"
  159.         .ItemData(.NewIndex) = &H7
  160.         .AddItem "Recent"
  161.         .ItemData(.NewIndex) = &H8
  162.         .AddItem "SendTo"
  163.         .ItemData(.NewIndex) = &H9
  164.         .AddItem "Bitbucket"
  165.         .ItemData(.NewIndex) = &HA
  166.         .AddItem "StartMenu"
  167.         .ItemData(.NewIndex) = &HB
  168.         .AddItem "DesktopDirectory"
  169.         .ItemData(.NewIndex) = &H10
  170.         .AddItem "Drives"
  171.         .ItemData(.NewIndex) = &H11
  172.         .AddItem "Network"
  173.         .ItemData(.NewIndex) = &H12
  174.         .AddItem "Nethood"
  175.         .ItemData(.NewIndex) = &H13
  176.         .AddItem "Fonts"
  177.         .ItemData(.NewIndex) = &H14
  178.         .AddItem "Templates"
  179.         .ItemData(.NewIndex) = &H15
  180.         .AddItem "Common StartMenu"
  181.         .ItemData(.NewIndex) = &H16
  182.         .AddItem "Common Programs"
  183.         .ItemData(.NewIndex) = &H17
  184.         .AddItem "Common Startup"
  185.         .ItemData(.NewIndex) = &H18
  186.         .AddItem "Common DestkopDirectory"
  187.         .ItemData(.NewIndex) = &H19
  188.         .AddItem "AppData"
  189.         .ItemData(.NewIndex) = &H1A
  190.         .AddItem "Printhood"
  191.         .ItemData(.NewIndex) = &H1B
  192.         .ListIndex = 0
  193.     End With
  194.     cboWalk.ListIndex = 2
  195.     txtPath = GetTempDir
  196. End Sub
  197.  
  198. Private Sub Form_Activate()
  199.     chkPath_Click
  200. End Sub
  201.  
  202. Private Sub chkPath_Click()
  203.     If chkPath Then
  204.         txtPath.Enabled = True
  205.         txtPath.SetFocus
  206.         lstSpecial.Enabled = False
  207.         cmdWalkDirs.Enabled = True
  208.         cmdWalkDir.Enabled = True
  209.     Else
  210.         txtPath.Enabled = False
  211.         lstSpecial.Enabled = True
  212.         cmdWalkDirs.Enabled = False
  213.         cmdWalkDir.Enabled = False
  214.     End If
  215. End Sub
  216.  
  217. Private Sub cmdBrowse_Click()
  218.     txtPath = BrowseForFolder(, , , "Starting Folder", CSIDL_DRIVES)
  219. End Sub
  220.  
  221. Private Sub cmdContext_Click()
  222.     If chkPath Then
  223.         With txtPath
  224.             ContextPopMenu hWnd, .Text, .Left, .Top
  225.         End With
  226.     Else
  227.         With lstSpecial
  228.             ContextPopMenu hWnd, .ItemData(.ListIndex), .Left, .Top
  229.         End With
  230.     End If
  231. End Sub
  232.  
  233. Private Sub cmdStop_Click()
  234.     fStop = True
  235. End Sub
  236.  
  237. Private Sub cmdWalkDir_Click()
  238.     txtOut = "Walk one directory: " & sCrLfCrLf
  239.     fStop = False
  240.     fWalkAll = False
  241.     Dim c As Long
  242.     WalkFiles Me, WalkType(cboWalk.ListIndex), txtPath, c
  243.     txtOut = txtOut & vbCrLf & "File count: " & c & vbCrLf
  244.     txtOut.SelStart = Len(txtOut)
  245. End Sub
  246.  
  247. Private Sub cmdWalkDirs_Click()
  248.     txtOut = "Walk directories recursively: " & sCrLfCrLf
  249.     fWalkAll = True
  250.     WalkAllFiles Me, WalkType(cboWalk.ListIndex), txtPath
  251. End Sub
  252.  
  253. Private Sub cmdWalkFolder_Click()
  254.     Dim folder As IVBShellFolder
  255.     txtOut = "Walk one folder: " & sCrLfCrLf
  256.     fWalkAll = False
  257.     If chkPath Then
  258.         Set folder = FolderFromItem(txtPath)
  259.     Else
  260.         With lstSpecial
  261.             Set folder = FolderFromItem(.ItemData(.ListIndex))
  262.         End With
  263.     End If
  264.     Dim c As Long
  265.     WalkFolders folder, Me, c, WalkType(cboWalk.ListIndex)
  266.     txtOut = txtOut & vbCrLf & "File count: " & c & vbCrLf
  267.     txtOut.SelStart = Len(txtOut)
  268. End Sub
  269.  
  270. Function WalkType(ByVal i As Integer) As EWalkMode
  271.     Select Case i
  272.     Case 0
  273.         WalkType = ewmFolders
  274.     Case 1
  275.         WalkType = ewmNonfolders
  276.     Case 2
  277.         WalkType = ewmBoth
  278.     End Select
  279. End Function
  280.  
  281. Private Sub cmdWalkFolders_Click()
  282.     Dim folder As IVBShellFolder
  283.     txtOut = "Walk folders recursively: " & sCrLfCrLf
  284.     fStop = False
  285.     fWalkAll = True
  286.     If chkPath Then
  287.         Set folder = FolderFromItem(txtPath)
  288.     Else
  289.         With lstSpecial
  290.             Set folder = FolderFromItem(.ItemData(.ListIndex))
  291.         End With
  292.     End If
  293.     WalkAllFolders folder, Me, 0, WalkType(cboWalk.ListIndex)
  294. End Sub
  295.  
  296. Private Sub Form_MouseUp(Button As Integer, Shift As Integer, _
  297.                          X As Single, Y As Single)
  298.     If Button And 2 Then
  299.         With lstSpecial
  300.             ContextPopMenu hWnd, .ItemData(.ListIndex), .Left, .Top
  301.         End With
  302.     End If
  303. End Sub
  304.  
  305.  
  306. Private Sub txtPath_GotFocus()
  307.     txtPath.SelStart = 0
  308.     txtPath.SelLength = 256
  309. End Sub
  310.  
  311. Private Function IUseFolder_UseFolder(UserData As Variant, _
  312.                                       CurFolder As IVBShellFolder, _
  313.                                       ByVal ItemList As Long) As Boolean
  314. ' Turn folder and pidl into CFileInfo
  315. With FileInfoFromFolder(CurFolder, ItemList)
  316.     Dim s As String, sSize As String
  317.     ' Don't show size for directories
  318.     If (.Attributes And vbDirectory) = 0 Then
  319.         sSize = " : " & Format$(.Length, "#,##0")
  320.     End If
  321.     ' Display different information for single or recursive walk
  322.     If fWalkAll Then
  323.         s = Space$(UserData * 4) & .DisplayName & " (" & _
  324.             .TypeName & ") " & .Modified & sSize & vbCrLf
  325.     Else
  326.         UserData = UserData + 1
  327.         s = .DisplayName & " (" & .TypeName & ") " & _
  328.             .Modified & sSize & vbCrLf
  329.     End If
  330.     txtOut = txtOut & s
  331.     txtOut.SelStart = Len(txtOut)
  332.     ' Let other windows process so we can recognize stop flag
  333.     DoEvents
  334.     If fStop Then IUseFolder_UseFolder = True
  335. End With
  336. End Function
  337.  
  338. Private Function IUseFile_UseFile(UserData As Variant, _
  339.                                   FilePath As String, _
  340.                                   FileInfo As CFileInfo) As Boolean
  341. With FileInfo
  342.     Dim s As String, sSize As String
  343.     If (.Attributes And vbDirectory) = 0 Then
  344.         sSize = " : " & Format$(.Length, "#,##0")
  345.     End If
  346.     If fWalkAll Then
  347.         s = Space$((UserData - 1) * 4) & .DisplayName & " (" & _
  348.             .TypeName & ") " & .Modified & sSize & vbCrLf
  349.     Else
  350.         UserData = UserData + 1
  351.         s = .DisplayName & " (" & .TypeName & ") " & _
  352.             .Modified & sSize & vbCrLf
  353.     End If
  354.     txtOut = txtOut & s
  355.     txtOut.SelStart = Len(txtOut)
  356.     DoEvents
  357.     If fStop Then IUseFile_UseFile = True
  358. End With
  359. End Function
  360.  
  361.